home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / pc_files / mktdata / econdata / docutils / bump.h < prev    next >
C/C++ Source or Header  |  1992-02-10  |  5KB  |  124 lines

  1. */              Class declarations for 
  2.                        BUMP 1.1
  3.         the Beginners Understandable Matrix Package
  4.                     for Borland C++
  5. */
  6.  
  7. class vorm // General Class for deriving Vector or Matrix classes
  8. {
  9.     protected:
  10.     int which;    // Identifier for debugging; set = to vcount at creation;
  11.     int nr;        // Number of rows
  12.     int nc;        // Number of columns
  13.     int fr;        // First row
  14.     int fc;        // First column
  15.     int lr;        // Last row
  16.     int lc;        // Last column
  17.     char temp;    // temp = 'y' is vector is temporary, otherwise 'n'
  18.  
  19.     /*    freeh() frees the heap memory used for the object.  It must
  20.         be written differently for matrices and vectors, but freet()
  21.         (described below) looks the same for the two classes, except that the
  22.         freeh() it calls is different.  Hence, freeh() is a good candidate to
  23.         be a virtual function.  The user may also call freeh() to free up the
  24.         heap that was need for an object that was needed for several uses but
  25.         is then no longer needed after a certain point in the program. 
  26.         Hence, freeh() is public.  */
  27.  
  28.     public:
  29.     virtual void freeh(){return;} 
  30.  
  31.     /*     freet() frees the heap memory used by objects created by operators
  32.         when those objects are used by other operators. Thus, in the line
  33.         "C = A + B;" the + first creates a temporary to hold A + B. The =
  34.         then copies this temporary to C and deletes the temporary by a
  35.         call to freet().  In the line "A = B", the = operator will also
  36.         call freet, but since B is not temporary, freet() returns without
  37.         calling freeh() to do the deletion. */
  38.  
  39.     protected:
  40.     void freet(){if(temp == 'y') freeh();} 
  41.     public:
  42.     int rows(){return nr;}
  43.     int columns(){return nc;}
  44.     int firstrow(){return fr;}
  45.     int firstcolumn(){return fc;}
  46.     int lastrow(){return lr;}
  47.     int lastcolumn(){return lc;}
  48.     };
  49.  
  50. class Matrix;  // This line allows the "friends" of Vector to refer to Matrix.
  51.  
  52. class Vector : public vorm
  53. {
  54.     int nelem;    // Number of elements
  55.     float *v;    // pointer to the vector itself
  56.  
  57.     public:
  58.     int ReadA(char *filename); // Read ASCII from a file.
  59.     void Display(char *title = "",int width = 8, int decimalPlaces = 2);
  60.     Vector(int anr, int anc = 1, char atemp = 'n', int afr = 1, int afc = 1);
  61.     Vector(Vector& a);
  62.      ~Vector();
  63.     Vector& operator = (Vector& ROp);
  64.     Vector operator - (Vector &a);
  65.     Vector operator ~ (); // Transposition
  66.     void freeh(); // free heap memory 
  67.     float& operator [] (int i);    // range checked element
  68.     friend void operator << (Matrix& a, Vector& b);
  69.     friend Vector operator + (Vector& a, Vector& b);
  70.     friend Matrix operator * (Vector& a, Vector& b);    // ab
  71.     friend Vector operator * (Matrix& a, Vector& b);
  72.     friend Vector operator * (Vector& a, Matrix& b);
  73.     friend Vector operator * (float a, Vector& b);
  74.     friend Vector operator / (Vector& a, float b);
  75.     // a/b forms the product a'b without creating a'.
  76.     friend Matrix operator / (Vector& a, Vector& b);    // a'b
  77.     friend Vector operator / (Matrix& A, Vector& b);    // A'b
  78.     friend Vector operator / (Vector& a, Matrix& b);    // a'B
  79.     };
  80.  
  81. class Matrix : public vorm
  82. {
  83.     float **m;
  84.  
  85.     public:
  86.     int ReadA(char *filename); // Read ASCII from a file.
  87.     void Display(char *title = "",int width = 8, int decimalPlaces = 2);
  88.      /*     Invert this matrix; return determinant.  Start row reduction with
  89.          the pivot in row startrow and stop when the pivot has been done
  90.          for row endrow.  If stratrow is 0, start with first row; if
  91.          endrow is 0, end with last row.  */
  92.  
  93.     double invert(int startrow = 0, int endrow = 0); 
  94.     Matrix(int anr, int anc, char atemp = 'n', int afr = 1, int afc = 1);
  95.     Matrix(Matrix& a);
  96.     ~Matrix();
  97.     Matrix& operator = (Matrix& a);
  98.     Matrix operator ~ ();  // Transposition
  99.     Matrix operator ! ();  // Inversion
  100.     float * operator [] (int i);    // range-checked pointer to row
  101.     void freeh(); // free heap memory 
  102.     friend void operator << (Matrix& a, Vector& b);
  103.     friend Matrix operator + (Matrix& a, Matrix& b);
  104.     friend Matrix operator - (Matrix& a, Matrix& b);
  105.     friend Matrix operator * (Matrix& a, Matrix& b);
  106.     friend Vector operator * (Vector& a, Matrix& b);
  107.     friend Vector operator * (Matrix& a, Vector& b);
  108.     friend Matrix operator * (Vector& a, Vector& b);
  109.     friend Matrix operator * (float a, Matrix& b);
  110.     friend Matrix operator / (Matrix& b, float a);
  111.     friend Matrix operator / (Matrix& a, Matrix& b); // form A'B without ~A
  112.     friend Vector operator / (Matrix& A, Vector& b); // A'b
  113.     friend Vector operator / (Vector& a, Matrix& b); // a'B
  114.     friend Matrix operator / (Vector& a, Vector& b); // a'b
  115.     };
  116. // other prototypes
  117. int isnum(char c);
  118. int getfloat(float& f, FILE *fp, char *s, int& j);
  119. int min(int a, int b);
  120. int max(int a, int b);
  121.  
  122. #define OK 1
  123. #define ERR -1
  124.